<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.7"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Over The Air (OTA) Bootloader Abstraction Library: Over The Air(OTA) Bootloader Abstraction Library Overview</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="infineon_logo.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Over The Air (OTA) Bootloader Abstraction Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.7 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li class="current"><a href="index.html"><span>Home</span></a></li>
      <li><a href="modules.html"><span>API&#160;Reference</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;"
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('index.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Over The Air(OTA) Bootloader Abstraction Library Overview </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This library assists in managing over-the-air (OTA) updates for application code that runs on various devices, including PSoC™ 6 Connectivity Devices, 20829 (CYW920829M2EVK-02) Devices, 89829 (CYW989829M2EVB-01) Devices, XMC7200 (KIT_XMC72_EVK, KIT_XMC72_EVK_MUR_43439M2) Devices, XMC7100 (KIT_XMC71_EVK_LITE_V1) Devices, and CYW955913SDCM2WLIPA (CYW955913EVK-01) Devices, depending on the chosen bootloader. The library implements storage interface APIs required by ota-update library to complete OTA on supported platforms. Current version(v1.X) of <b>ota-bootloader-abstraction</b> has storage interface APIs for MCUBootloader and in-built Bootloader (CYW955913SDCM2WLIPA platform) based OTA.<br />
 The ModusToolbox MCUBootloader and in-built Bootloader (CYW955913SDCM2WLIPA platform) based OTA code examples import this library automatically along with ota-update library.</p>
<h1><a class="anchor" id="section_features"></a>
Features and Functionality</h1>
<p>This library has implementation of storage interface APIs required by ota-update library to complete OTA on supported platforms. </p>
<p><b>Other features:</b></p><ul>
<li>Template flashmaps for supported platforms.</li>
<li>Template OTA linker files for supported platforms and toolchains.</li>
<li>Prebuild and Postbuild scripts for generating BOOT and UPGRADE images of OTA Application.</li>
<li>OTA image signing scripts.</li>
</ul>
<h1><a class="anchor" id="section_notes"></a>
Integration Notes</h1>
<p>To add different bootloader support on Infineon connectivity-enabled MCU platforms, ota-update library offloads bootloader dependent storage interface APIs using callback mechanism. To handle downloaded OTA upgrade images ota-update library calls registered storage interface callbacks. This ota-bootloader-abstraction library provides implementation of these storage interface APIs for different bootloaders along with build environment required to generate BOOT and UPGRADE images of OTA applications. Current version of library supports only MCUBootloader and in-built bootloader (CYW955913SDCM2WLIPA platform) based OTA image handling. <br />
 </p>
<p><b>1. MCUBootloader</b> <br />
 The user is expected to:</p><ol type="1">
<li>Build and program MCUBootApp on the chosen platform(s) before enabling MCUBootloader based OTA in an application. Refer to MCUBOOT_APP_README.md in ota-bootloader-abstraction/&lt;version&gt;/source/COMPONENT_MCUBOOT/.<br />
</li>
<li>Update OTA Application Makefile by referring OTA Bootloader Abstraction Makefile Readme MCUBOOT_OTA_MAKEFILE_INFO_README.md in ota-bootloader-abstraction/&lt;version&gt;/source/COMPONENT_MCUBOOT/.<br />
</li>
<li><b>ota-bootloader-abstraction</b> library has makefile <b>mcuboot_support.mk</b> located in ota-bootloader-abstraction/&lt;version&gt;/makefiles/mcuboot/ which has necessary pre and post build scripts for generating MCUBootloader based BOOT and UPGRADE images of OTA application.<br />
</li>
<li>Include <b>mcuboot_support.mk</b> from OTA Application Makefile.<br />
</li>
<li>Configure OTA storage interface callback APIs in OTA application, And pass the same storage interface while starting OTA agent.<br />
</li>
<li>OTA storage interface calls Flash operations(Read, Write, erase) to store upgrade images in UPGRADE slot. <b>ota-bootloader-abstraction</b> provides template flash operations implemention(Using <b>mtb-pdl-cat1</b> library APIs) and implementation is available in configs folder ota-bootloader-abstraction/&lt;version&gt;/configs/COMPONENT_MCUBOOT/flash/. User can use template implementation by copying contents of ota-bootloader-abstraction/&lt;version&gt;/configs/COMPONENT_MCUBOOT/flash/ to application space or Can implement flash operation APIs defined in ota-bootloader-abstraction/&lt;version&gt;/source/COMPONENT_MCUBOOT/cy_ota_flash.h. <br />
</li>
<li>For <b>MCUBootloader based OTA Support</b>, add the following component to the project Makefile:<br />
<div class="fragment"><div class="line">COMPONENTS+=MCUBOOT </div>
</div><!-- fragment --> <br />
</li>
<li>Add <b>Application Build Directory</b> in the project Makefile:<br />
<div class="fragment"><div class="line">CY_BUILD_LOCATION=&lt;Application<span class="stringliteral">&#39;s Build Working Directory path&gt;</span></div>
</div><!-- fragment --> <br />
</li>
<li>Add <b>OTA platform</b> in the project Makefile:<br />
<div class="fragment"><div class="line">OTA_PLATFORM=&lt;platform_type&gt; </div>
</div><!-- fragment --> Refer OTA Bootloader Abstraction Makefile Readme &lt;mtb_shared&gt;/ota-bootloader-abstraction/&lt;version&gt;/source/COMPONENT_MCUBOOT/MCUBOOT_OTA_MAKEFILE_INFO_README.md.<br />
<br />
</li>
<li>Add <b>linker file path for MCUBootloader based OTA on choosen platform</b> in the project Makefile:<br />
<div class="fragment"><div class="line">OTA_LINKER_FILE=&lt;OTA linker file path&gt; </div>
</div><!-- fragment --> <br />
</li>
<li>There are other components that may be needed based on support. Please refer to the various readme files in ota-bootloader-abstraction/&lt;version&gt;/source/COMPONENT_MCUBOOT/.</li>
</ol>
<ul>
<li>MCUBOOT_APP_README.md<br />
</li>
<li>MCUBOOT_BUILD_COMMANDS.md<br />
</li>
<li>MCUBOOT_OTA_FLASH_LAYOUT_README.md<br />
</li>
<li>MCUBOOT_OTA_MAKEFILE_INFO_README.md<br />
</li>
<li>README.md in library root directory.</li>
</ul>
<p><b>2. CYW955913EVK-01 in-built Bootloader</b> <br />
 The user is expected to:<br />
</p><ol type="1">
<li>Update OTA Application Makefile by referring OTA Bootloader Abstraction Makefile Readme CYW955913SDCM2WLIPA_OTA_MAKEFILE_INFO_README.md in ota-bootloader-abstraction/&lt;version&gt;/source/COMPONENT_CYW955913SDCM2WLIPA/.<br />
</li>
<li>Configure OTA storage interface callback APIs in OTA application, And pass the same storage interface while starting OTA agent.<br />
</li>
<li>For <b>CYW955913EVK-01 in-built Bootloader based OTA Support</b>, add the following component to the project Makefile:<br />
<div class="fragment"><div class="line">COMPONENTS+=CYW955913SDCM2WLIPA </div>
</div><!-- fragment --> <br />
</li>
<li>Add <b>Application Build Directory</b> in the project Makefile:<br />
<div class="fragment"><div class="line">CY_BUILD_LOCATION=&lt;Application<span class="stringliteral">&#39;s Build Working Directory path&gt;</span></div>
</div><!-- fragment --> <br />
</li>
<li>There are other components that may be needed based on support. Please refer to the various readme files in ota-bootloader-abstraction/&lt;version&gt;/source/COMPONENT_CYW955913SDCM2WLIPA/.</li>
</ol>
<ul>
<li>CYW955913SDCM2WLIPA_OTA_MAKEFILE_INFO_README.md<br />
</li>
<li>README.md in library root directory.<br />
</li>
</ul>
<h1><a class="anchor" id="section_concept"></a>
General Concept</h1>
<p>The OTA Bootloader Abstraction provides bootloader specific storage interface API implementation which can be used with <b>ota-update</b> library for handling downloaded OTA application upgrade images. In case of MCUBootloader, during reboot bootloader validates and boots upgrade image and in case of CYW955913EVK-01 in-built Bootloader, the in-built bootloader validates the downloaded image then reboots with upgrade image. <br />
 </p>
<p><b>1. MCUBootloader</b> </p>
<p><b>1.1 Basic device boot sequence</b></p><ol type="1">
<li>ROM boot will start Bootloader.<br />
</li>
<li>Bootloader runs the current application(BOOT Image) in the Primary slot.<br />
</li>
<li>The OTA Agent downloads the update(UPGRADE Image) and stores it in the Secondary slot using storage interface APIs.<br />
</li>
<li>The OTA Agent marks the upgrade as ready using storage interface API.<br />
 <b>On the next system boot</b> <br />
</li>
</ol>
<ol type="1">
<li>ROM boot will start Bootloader.<br />
</li>
<li>If no update is downloaded, Bootloader starts the current application.<br />
</li>
<li>Bootloader determines if there is an update in the Secondary Slot.<br />
</li>
<li>If there is an update available<br />
 a. Bootloader verifies the update.<br />
 b. Bootloader boots upgrade image either by copying or switching Primary and Secondary Slots.<br />
 c. The updated application must call cy_ota_storage_validated() to validate the update.<br />
 </li>
</ol>
<p><b>1.2 MCUBootloader Support</b><br />
 This library has below support for MCUBootloader based OTA on PSoC6, 20829, 89829, XMC7100, and XMC7200 platforms.</p><ol type="1">
<li>Template flashmaps for PSoC6, 20829, 89829, XMC7100, and XMC7200 platforms.<br />
</li>
<li>Template linker files for GCC_ARM, ARM, and IAR toolchains.<br />
</li>
<li>Storage operation callback APIs to handle MCUBootloader based upgrade image.<br />
</li>
<li>Prebuild and Postbuild scripts for generating and signing MCUBootloader based BOOT and UPGRADE image of an OTA Application.<br />
 </li>
</ol>
<p><b>2. CYW955913EVK-01 in-built Bootloader</b> </p>
<p><b>2.1 Basic device boot sequence</b></p><ol type="1">
<li>ROM boot will start the CYW955913EVK-01 in-built Bootloader.<br />
</li>
<li>CYW955913EVK-01 in-built Bootloader starts the current application in Active DS.<br />
</li>
<li>If there is an update available in Non Active DS,<br />
 a. CYW955913EVK-01 in-built Bootloader verifies the update image headers and certificates.<br />
 b. If a valid upgrade image is found, the CYW955913EVK-01 in-built Bootloader will activate the non-active DS and deactivate the active DS.<br />
 c. On reset, CYW955913EVK-01 in-built Bootloader starts the application in Active DS.<br />
 </li>
</ol>
<p><b>2.2 CYW955913EVK-01 in-built Bootloader Support</b><br />
 This library has below support for in-built bootloader based platforms like CYW955913EVK-01.</p><ol type="1">
<li>Storage operation callback APIs to handle CYW955913EVK-01 in-built Bootloader based upgrade image.</li>
</ol>
<h1><a class="anchor" id="section_api_overview"></a>
API Overview</h1>
<h2>1. Initialize Storage Area </h2>
<p><code><a class="el" href="group__group__ota__bootsupport__functions.html#gad1e6294598ad971d3cb35eb789ea4b7b" title="Initialize Storage area. ">cy_ota_storage_init()</a></code> - Initializes flash, QSPI flash, or any other external memory type.<br />
 Application is expected to call this API once before starting OTA agent.<br />
 <code>cy_rslt_t <a class="el" href="group__group__ota__bootsupport__functions.html#gad1e6294598ad971d3cb35eb789ea4b7b" title="Initialize Storage area. ">cy_ota_storage_init(void)</a>;</code></p>
<h2>2. Open Storage Area </h2>
<p><code><a class="el" href="group__group__ota__bootsupport__functions.html#gade56090dfaf908e2aa14a35d1ace6b06" title="Open storage area for storing OTA UPGRADE images. ">cy_ota_storage_open()</a></code> - Open storage Area for storing OTA UPGRADE images.<br />
 Typically, this erases UPGRADE slots as well. The OTA agent will call this API once OTA image download starts.<br />
 <code>cy_rslt_t <a class="el" href="group__group__ota__bootsupport__functions.html#gade56090dfaf908e2aa14a35d1ace6b06" title="Open storage area for storing OTA UPGRADE images. ">cy_ota_storage_open(cy_ota_storage_context_t *storage_ptr)</a>;</code></p>
<h2>3. Read data from Storage Area. </h2>
<p><code><a class="el" href="group__group__ota__bootsupport__functions.html#gae935166cb14ce63a64e6f58bafe1c2af" title="Read data from storage area. ">cy_ota_storage_read()</a></code> - Read data from Storage Area.<br />
 The Read API is primarily used by OTA agents to read OTA Image headers.<br />
 <code>cy_rslt_t <a class="el" href="group__group__ota__bootsupport__functions.html#gae935166cb14ce63a64e6f58bafe1c2af" title="Read data from storage area. ">cy_ota_storage_read(cy_ota_storage_context_t *storage_ptr, cy_ota_storage_read_info_t *chunk_info)</a>;</code></p>
<h2>4. Write data to Storage Area. </h2>
<p><code><a class="el" href="group__group__ota__bootsupport__functions.html#ga2636ed026fa43484ae0f24e74c6bc472" title="Write data to configured storage area. ">cy_ota_storage_write()</a></code> - Write data to Storage Area.<br />
 The Write API is mainly utilized by OTA agents to write OTA upgrade images that have been downloaded.<br />
 <code>cy_rslt_t <a class="el" href="group__group__ota__bootsupport__functions.html#ga2636ed026fa43484ae0f24e74c6bc472" title="Write data to configured storage area. ">cy_ota_storage_write(cy_ota_storage_context_t *storage_ptr, cy_ota_storage_write_info_t *chunk_info)</a>;</code></p>
<h2>5. Close Storage Area. </h2>
<p><code><a class="el" href="group__group__ota__bootsupport__functions.html#ga7148e14b70eec5343c693dc92147e257" title="Close Storage area for download. ">cy_ota_storage_close()</a></code> - Close Storage Area.<br />
 This API is responsible for closing the storage context. After the context is closed, it will not be possible to perform any write or read operations.<br />
 <code>cy_rslt_t <a class="el" href="group__group__ota__bootsupport__functions.html#ga7148e14b70eec5343c693dc92147e257" title="Close Storage area for download. ">cy_ota_storage_close(cy_ota_storage_context_t *storage_ptr)</a>;</code></p>
<h2>6. Verify downloaded UPGRADE OTA image. </h2>
<p><code><a class="el" href="group__group__ota__bootsupport__functions.html#gafec15fe9e456d05c41e5e8803d18193d" title="Verify downloaded UPGRADE OTA image. ">cy_ota_storage_verify()</a></code> - Verify OTA image.<br />
 The OTA agent provides an application callback for image verification before invoking this API.<br />
 <code>cy_rslt_t <a class="el" href="group__group__ota__bootsupport__functions.html#gafec15fe9e456d05c41e5e8803d18193d" title="Verify downloaded UPGRADE OTA image. ">cy_ota_storage_verify(cy_ota_storage_context_t *storage_ptr)</a>;</code></p>
<h2>7. Validate currently running APP. </h2>
<p><code>cy_ota_storage_validated()</code> - Validates currently executing application and makes it boot image until next upgrade is available.<br />
 The application is expected to call this API to execute an image as the boot image until the next upgrade image becomes available.<br />
 <code>cy_rslt_t cy_ota_storage_validated(void);</code></p>
<h2>8. Get Application Image information </h2>
<p><code><a class="el" href="group__group__ota__bootsupport__functions.html#gac4a3664a8d4f9e33e3bcc877e78f84f8" title="Get Application image information. ">cy_ota_storage_get_app_info()</a></code> - Get Application version, Application ID information.<br />
 The header of an application image (BOOT/UPGRADE) typically includes the following information.<br />
 <code>cy_rslt_t <a class="el" href="group__group__ota__bootsupport__functions.html#gac4a3664a8d4f9e33e3bcc877e78f84f8" title="Get Application image information. ">cy_ota_storage_get_app_info(void* file_des, cy_ota_app_info_t *app_info)</a>;</code></p>
<h1><a class="anchor" id="section_snippets"></a>
Code Snippets</h1>
<p><b>1. Override Default Flash operations API implementation:</b><br />
 Copy flash operation implementations from folder ota-bootloader-abstraction/&lt;version&gt;/configs/COMPONENT_MCUBOOT/flash directory to the top-level code example directory in the project. Change these implementation if required.<br />
 </p><div class="fragment"><div class="line"></div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Copy flash operation flash implementations from &#39;&lt;ota-bootloader-abstraction&gt;/configs/COMPONENT_MCUBOOT/flash/&#39; to application space.</span></div>
<div class="line"><span class="comment"> * Change default implementation if required.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"></div>
<div class="line">cy_rslt_t <a class="code" href="group__group__ota__bootsupport__functions.html#ga8992438c302b7b07295524c1ff9a1103">cy_ota_mem_init</a>(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">/*</span></div>
<div class="line"><span class="comment">     * Implement code logic to Initialize flash, QSPI flash, or any other external memory type</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line">    <span class="keywordflow">return</span> CY_RSLT_SUCCESS;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">cy_rslt_t <a class="code" href="group__group__ota__bootsupport__functions.html#gaee479d591db0b2861504f1753fac752d">cy_ota_mem_read</a>(<a class="code" href="group__group__ota__bootsupport__typedefs.html#gaab757db963c4503260e549eadfdbaf09">cy_ota_mem_type_t</a> mem_type, uint32_t addr, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> len)</div>
<div class="line">{</div>
<div class="line">    UNUSED_ARG(mem_type);</div>
<div class="line">    UNUSED_ARG(addr);</div>
<div class="line">    UNUSED_ARG(data);</div>
<div class="line">    UNUSED_ARG(len);</div>
<div class="line"></div>
<div class="line">    <span class="comment">/*</span></div>
<div class="line"><span class="comment">     * Implement code logic to read from flash, QSPI flash, or any other external memory type</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> CY_RSLT_SUCCESS;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">cy_rslt_t <a class="code" href="group__group__ota__bootsupport__functions.html#ga9faaf895a1256d1406c9727e8f3cf991">cy_ota_mem_write</a>(<a class="code" href="group__group__ota__bootsupport__typedefs.html#gaab757db963c4503260e549eadfdbaf09">cy_ota_mem_type_t</a> mem_type, uint32_t addr, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> len)</div>
<div class="line">{</div>
<div class="line">    UNUSED_ARG(mem_type);</div>
<div class="line">    UNUSED_ARG(addr);</div>
<div class="line">    UNUSED_ARG(data);</div>
<div class="line">    UNUSED_ARG(len);</div>
<div class="line"></div>
<div class="line">    <span class="comment">/*</span></div>
<div class="line"><span class="comment">     * Implement code logic to write data to flash, QSPI flash, or any other external memory type</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> CY_RSLT_SUCCESS;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">cy_rslt_t <a class="code" href="group__group__ota__bootsupport__functions.html#gaff6ed4e415f3d05be3266208316daf86">cy_ota_mem_erase</a>(<a class="code" href="group__group__ota__bootsupport__typedefs.html#gaab757db963c4503260e549eadfdbaf09">cy_ota_mem_type_t</a> mem_type, uint32_t addr, <span class="keywordtype">size_t</span> len)</div>
<div class="line">{</div>
<div class="line">    UNUSED_ARG(mem_type);</div>
<div class="line">    UNUSED_ARG(addr);</div>
<div class="line">    UNUSED_ARG(len);</div>
<div class="line"></div>
<div class="line">    <span class="comment">/*</span></div>
<div class="line"><span class="comment">     * Implement code logic to erase flash, QSPI flash, or any other external memory type</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> CY_RSLT_SUCCESS;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">size_t</span> <a class="code" href="group__group__ota__bootsupport__functions.html#gac32ab4f247a4d4cee8a65ee9ce38e0d5">cy_ota_mem_get_prog_size</a>(<a class="code" href="group__group__ota__bootsupport__typedefs.html#gaab757db963c4503260e549eadfdbaf09">cy_ota_mem_type_t</a> mem_type, uint32_t addr)</div>
<div class="line">{</div>
<div class="line">    UNUSED_ARG(mem_type);</div>
<div class="line">    UNUSED_ARG(addr);</div>
<div class="line"></div>
<div class="line">    <span class="comment">/*</span></div>
<div class="line"><span class="comment">     * Implement code logic to get programming page size of flash, QSPI flash, or any other external memory type</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> CY_RSLT_SUCCESS;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">size_t</span> <a class="code" href="group__group__ota__bootsupport__functions.html#ga9acc08068e0389f280ee19a67b84a7d6">cy_ota_mem_get_erase_size</a>(<a class="code" href="group__group__ota__bootsupport__typedefs.html#gaab757db963c4503260e549eadfdbaf09">cy_ota_mem_type_t</a> mem_type, uint32_t addr)</div>
<div class="line">{</div>
<div class="line">    UNUSED_ARG(mem_type);</div>
<div class="line">    UNUSED_ARG(addr);</div>
<div class="line"></div>
<div class="line">    <span class="comment">/*</span></div>
<div class="line"><span class="comment">     * Implement code logic to get sector erase size flash, QSPI flash, or any other external memory type</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> CY_RSLT_SUCCESS;</div>
<div class="line">}</div>
<div class="line"></div>
</div><!-- fragment --><p> <br />
 <b>2. Registering Storage Interface APIs:</b><br />
 The following code snippet demonstrates an example for initializing the cy_ota_storage_interface_t structure which is required to start the OTA Agent.<br />
 This example functions also demonstrates the usage of the OTA Storage Interface APIs for Upgrade image handling (read/write/validate) callback functions.<br />
 </p><div class="fragment"><div class="line"><span class="comment">/* Macro to enable/disable TLS. */</span></div>
<div class="line"><span class="preprocessor">#define ENABLE_TLS          (false)</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define HTTP_SERVER         &quot;my.httpserver.com&quot;</span></div>
<div class="line"><span class="preprocessor">#define HTTP_SERVER_PORT    (80)                </span><span class="comment">/* 443 for TLS. */</span><span class="preprocessor"></span></div>
<div class="line"></div>
<div class="line"><span class="comment">/* Number of MQTT topic filters. */</span></div>
<div class="line"><span class="preprocessor">#define MQTT_TOPIC_FILTER_NUM   (1)</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define MQTT_BROKER         &quot;mqtt.broker.com&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define MQTT_BROKER_PORT    (1883)              </span><span class="comment">/* (8883) for TLS support. */</span><span class="preprocessor"></span></div>
<div class="line"><span class="comment">/* MQTT topics. */</span></div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span> * mqtt_topics[ MQTT_TOPIC_FILTER_NUM ] =</div>
<div class="line">{</div>
<div class="line">        <span class="stringliteral">&quot;mtb/test/ota/image&quot;</span></div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"><span class="comment">/* Root CA Certificate.</span></div>
<div class="line"><span class="comment">   Must include the PEM header and footer:</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">        &quot;-----BEGIN CERTIFICATE-----\n&quot; \</span></div>
<div class="line"><span class="comment">        &quot;.........base64 data.......\n&quot; \</span></div>
<div class="line"><span class="comment">        &quot;-----END CERTIFICATE-------\n&quot;</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"><span class="preprocessor">#define ROOT_CA_CERTIFICATE     &quot;&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">/* Client Certificate.</span></div>
<div class="line"><span class="comment">   Must include the PEM header and footer:</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">        &quot;-----BEGIN CERTIFICATE-----\n&quot; \</span></div>
<div class="line"><span class="comment">        &quot;.........base64 data.......\n&quot; \</span></div>
<div class="line"><span class="comment">        &quot;-----END CERTIFICATE-------\n&quot;</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"><span class="preprocessor">#define CLIENT_CERTIFICATE      &quot;&quot;</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">/* Private Key.</span></div>
<div class="line"><span class="comment">   Must include the PEM header and footer:</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">        &quot;-----BEGIN RSA PRIVATE KEY-----\n&quot; \</span></div>
<div class="line"><span class="comment">        &quot;...........base64 data.........\n&quot; \</span></div>
<div class="line"><span class="comment">        &quot;-----END RSA PRIVATE KEY-------\n&quot;</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"><span class="preprocessor">#define CLIENT_KEY              &quot;&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">/* OTA context. */</span></div>
<div class="line"><span class="keyword">static</span> cy_ota_context_ptr ota_context;</div>
<div class="line"></div>
<div class="line"><span class="comment">/* OTA callback function define. */</span></div>
<div class="line">cy_ota_callback_results_t ota_callback(cy_ota_cb_struct_t *cb_data);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">/* network parameters for OTA. */</span></div>
<div class="line">cy_ota_network_params_t     network_params = { CY_OTA_CONNECTION_UNKNOWN };</div>
<div class="line"></div>
<div class="line"><span class="comment">/* Parameters for the OTA Agent. */</span></div>
<div class="line">cy_ota_agent_params_t ota_agent_params =</div>
<div class="line">{</div>
<div class="line">    .cb_func = ota_callback,                <span class="comment">/* Set the value to NULL if the callback function is not used. */</span></div>
<div class="line">    .cb_arg = &amp;ota_context,                 <span class="comment">/* Set the value to NULL if the callback function is not used. */</span></div>
<div class="line">    .reboot_upon_completion = 1             <span class="comment">/* Reboot after completing OTA with success. */</span></div>
<div class="line">};</div>
<div class="line"></div>
<div class="line">cy_ota_storage_interface_t ota_interfaces =</div>
<div class="line">{</div>
<div class="line">   .ota_file_open            = <a class="code" href="group__group__ota__bootsupport__functions.html#gade56090dfaf908e2aa14a35d1ace6b06">cy_ota_storage_open</a>,</div>
<div class="line">   .ota_file_read            = <a class="code" href="group__group__ota__bootsupport__functions.html#gae935166cb14ce63a64e6f58bafe1c2af">cy_ota_storage_read</a>,</div>
<div class="line">   .ota_file_write           = <a class="code" href="group__group__ota__bootsupport__functions.html#ga2636ed026fa43484ae0f24e74c6bc472">cy_ota_storage_write</a>,</div>
<div class="line">   .ota_file_close           = <a class="code" href="group__group__ota__bootsupport__functions.html#ga7148e14b70eec5343c693dc92147e257">cy_ota_storage_close</a>,</div>
<div class="line">   .ota_file_verify          = <a class="code" href="group__group__ota__bootsupport__functions.html#gafec15fe9e456d05c41e5e8803d18193d">cy_ota_storage_verify</a>,</div>
<div class="line">   .ota_file_validate        = cy_ota_storage_validated,</div>
<div class="line">   .ota_file_get_app_info    = <a class="code" href="group__group__ota__bootsupport__functions.html#gac4a3664a8d4f9e33e3bcc877e78f84f8">cy_ota_storage_get_app_info</a></div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">/* BSP Init */</span></div>
<div class="line"></div>
<div class="line">    <span class="comment">/* Memory Init */</span></div>
<div class="line"></div>
<div class="line">    <span class="comment">/* Start OTA Agent.*/</span></div>
<div class="line">    result = cy_ota_agent_start(&amp;ota_test_network_params, &amp;ota_test_agent_params, &amp;ota_interfaces, &amp;ota_context);</div>
<div class="line">    <span class="keywordflow">if</span> (result != CY_RSLT_SUCCESS)</div>
<div class="line">    {</div>
<div class="line">        printf(<span class="stringliteral">&quot;Agent start Failed - result: 0x%lx\n&quot;</span>, result);</div>
<div class="line">        <span class="keywordflow">while</span> (<span class="keyword">true</span>)</div>
<div class="line">        {</div>
<div class="line">            cy_rtos_delay_milliseconds(10);</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --><h1><a class="anchor" id="section_example"></a>
ModusToolbox OTA Code Examples</h1>
<p>ModusToolbox OTA Example using MQTT: <a href="https://github.com/infineon/mtb-example-ota-mqtt">https://github.com/infineon/mtb-example-ota-mqtt</a><br />
 ModusToolbox OTA Update Bluetooth® example: <a href="https://github.com/infineon/mtb-example-btstack-freertos-cyw20829-keyboard">https://github.com/infineon/mtb-example-btstack-freertos-cyw20829-keyboard</a><br />
 MCUboot documentation: <a href="https://github.com/JuulLabs-OSS/mcuboot/blob/cypress/docs/design.md">https://github.com/JuulLabs-OSS/mcuboot/blob/cypress/docs/design.md</a> <br />
</p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>Over The Air (OTA) Bootloader Abstraction Library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
</body>
</html>
